﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Global;
using System.Collections.ObjectModel;
using System.Reflection;

namespace Clipper.ClipperUserControl
{
    /// <summary>
    /// UserDetectReport.xaml 的交互逻辑
    /// </summary>
    public partial class UserDetectReport : UserControl
    {
        #region 变量
        BLL.DetectResult mDetectReportBll = new BLL.DetectResult();
        ObservableCollection<Model.DetectResult> mReportList = null;
        BLL.DetectVariety mDetectVarietyBll = new BLL.DetectVariety();
        public UserDetectReport()
        {
            InitializeComponent();
        }
        #endregion

        public void DataBind()
        {
            if (cboDetectVariety.ItemsSource == null)
            {
                cboDetectVariety.ItemsSource = mDetectVarietyBll.GetModelList("");
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            DateTime? start = null;
            DateTime? end = null;
            string strStart = "";
            string strEnd = "";
            int? sampleStart = null;
            int? sampleEnd = null;
            string name = "";
            int? patientStart = null;
            int? patientEnd = null;

            if (chkDate.IsChecked.Value)
            {
                strStart = dtpStart.SelectedDate.Value.ToString("yyyy-MM-dd");
                strEnd = dtpEnd.SelectedDate.Value.ToString("yyyy-MM-dd");
            }
            if (chkSample.IsChecked.Value)
            {
                sampleStart = txtSampleStart.Number;
                sampleEnd = txtSampleEnd.Number;
            }
            if (chkName.IsChecked.Value)
            {
                name = txtName.Text;
            }
            if (chkPatientId.IsChecked.Value)
            {
                patientStart = txtpatientStart.Number;
                patientEnd = txtpatientEnd.Number;
            }
            if (chkDetectVariety.IsChecked.Value)
            {

            }
            mReportList = mDetectReportBll.GetDetectReport(start, end, sampleStart, sampleEnd, name,
                 patientStart,patientEnd);

            if (mReportList != null)
            {
                gridDetectReport.ItemsSource = mReportList;
            }
        }

        private void dtpStart_LostFocus(object sender, RoutedEventArgs e)
        {
            DatePicker picker = sender as DatePicker;
            Type type = picker.GetType();
            FieldInfo info = type.GetField("_textBox",
                BindingFlags.NonPublic | BindingFlags.Instance);
            System.Windows.Controls.Primitives.DatePickerTextBox text =
               info.GetValue(picker) as System.Windows.Controls.Primitives.DatePickerTextBox;
            if (null != text)
            {
                text.VerticalAlignment = VerticalAlignment.Center;
                text.VerticalContentAlignment = VerticalAlignment.Center;
            }
        }
    }
}
